﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FirstExam_1011 {
    class ConcretePolygon {

        private rcn_testsEntities context = new rcn_testsEntities();

        public ConcretePolygon(int id) {
            context.Polygon.AddObject(Polygon.CreatePolygon(id));
            context.SaveChanges();
        }
        public int Id { get; private set; }
        public string Descricao { get; set; }
    }
    class ConcreteVertice {
        public int Id{get; set;}
        public int x { get; set; }
        public int y { get; set; }
    }

    class DataLayer {
        
        readonly rcn_testsEntities context = new rcn_testsEntities();

        public void CreatePolygon(int id, string desc) {
            Polygon p = Polygon.CreatePolygon(id);
            p.descricao = desc;
            context.AddToPolygon(p);
            context.SaveChanges();
        }

        public void CreatePolygon(int id, string desc, List<ConcreteVertice> vertices) {
             this(id, desc);
             int idx = 1;
             vertices.ForEach(v => {
                 Vertice.Add(Vertice.CreateVertice(v.Id, v.x, v.y, id));
             });
             context.SaveChanges();
        }

        public ConcretePolygon GetPolygon(int id) {
            Polygon pol = context.Polygon.First(p => p.idPol == id);
            return pol == null ? null : new ConcretePolygon { Id=pol.idPol, Descricao = pol.descricao };
        }
    }
}
